<?php

/**
 *  用户
 * @author xiaojy xiaojy@wanthings.com
 * @copyright 成都网信天成科技有限公司, 2016, http://www.wanthings.com
 */
class User extends BaseActiveRecord
{

    public $column_name = 'mobile';
    public $module_id = 'user';

    CONST STATUS_NORMAL = 1;    //正常
    CONST STATUS_DISABLE = 2;    //禁用

    CONST DEFAULT_PASSWORD = '123456';
    /*
     * 获得数据表方法
     * 重写父类方法tableName()
     */

    function tableName() {
        return "{{user}}";
    }

    /*
     * 获得当前类对象的方法model
     * 重写父类方法model
     */

    public static function model($className = __CLASS__) {
        return parent::model($className);
    }

    /**
     * Checks if the given password is correct.
     * @param string the password to be validated
     * @return boolean whether the password is valid
     */
    public function validatePassword($password)
    {

        if(md5($password)===$this->password) {
            return true;
        } else {
            return false;
        }
    }

    public function setPassword($password)
    {
        return md5($password);
    }


    public function behaviors()
    {
        return array(
            'UserBehavior' => array(
                'class' => 'application.behaviors.UserBehavior'
            ),
            'CTimestampBehavior' => array(
                'class' => 'zii.behaviors.CTimestampBehavior',
                'createAttribute' => 'ctime',
                'updateAttribute' => 'mtime',
                'setUpdateOnCreate'=> true,
            ),
            'UserTokenBehavior'=>array(
                'class'=>'application.behaviors.UserTokenBehavior'
            )

        );
    }


}